﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using System.Runtime.InteropServices;
using System.Windows.Interop;

using System.IO;
using System.Xml;
using System.Xml.XPath;

using System.ComponentModel;
using System.Windows.Controls.Primitives;




namespace Bainx.WPF.Extend.Control
{
    /// <summary>
    /// PictureBox.xaml 的交互逻辑
    /// </summary>
    public partial class PictureBox : UserControl
    {
        /// <summary>
        /// 关闭图片
        /// </summary>
        public event UriRoutedEventHandler Closeing;
        private Uri pictureUri;
        /// <summary>
        /// 展示的图片Uri
        /// </summary>
        public Uri PictureUri
        {
            get { return pictureUri; }
            set
            {
                ImageBrush ib = new ImageBrush(new BitmapImage(value));
                this.BackImage.Background = ib;
                pictureUri = value;
            }
        }
        /// <summary>
        /// 图片展示框
        /// </summary>
        public PictureBox()
        {
            InitializeComponent();
            this.CloseButton.Click += new RoutedEventHandler(CloseButton_Click);
        }
        /// <summary>
        ///  图片展示框
        /// </summary>
        /// <param name="pictureUri"></param>
        public PictureBox(Uri pictureUri)
            :this()
        {
            PictureUri = pictureUri;
        }

        void CloseButton_Click(object sender, RoutedEventArgs e)
        {
            Closeing(this, new UriRoutedEventArgs(pictureUri));            
        }
    }
    /// <summary>
    /// 传递Uri的路由事件句柄
    /// </summary>
    public delegate void UriRoutedEventHandler(object sender, UriRoutedEventArgs e);
    /// <summary>
    /// 传递Uri的路由事件参数
    /// </summary>
    public class UriRoutedEventArgs : RoutedEventArgs
    {
        /// <summary>
        /// 传递的Uri
        /// </summary>
        public Uri Uri { get; set; }
        /// <summary>
        /// 传递Uri的路由事件参数
        /// </summary>
        /// <param name="uri"></param>
        public UriRoutedEventArgs(Uri uri)
            : base()
        {
            Uri = uri;
        }
        /// <summary>
        /// 传递Uri的路由事件参数
        /// </summary>
        public UriRoutedEventArgs()
            : base()
        { }
    }
}
